{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gftEuRyPfWba"
      },
      "source": [
        "# **Amazon Recognition**"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ulfr855iguoO"
      },
      "outputs": [],
      "source": [
        "!pip install -q boto3"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "QzjUHWzDgxvc"
      },
      "outputs": [],
      "source": [
        "aws_access_key_id = \"your_aws_access_id\"\n",
        "aws_secret_access_key = \"your_aws_secret_key\"\n",
        "region_name=' '"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Z8wnRf_NgaAx",
        "outputId": "214d19d8-96ad-4f18-9ffb-2a22b55b8393"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Detected labels in /content/image.jpg\n",
            "Machine : 99.97028350830078[]\n",
            "Spoke : 99.97028350830078[]\n",
            "Bicycle : 99.5052261352539[{'BoundingBox': {'Width': 0.571449339389801, 'Height': 0.5124862194061279, 'Left': 0.16833741962909698, 'Top': 0.22136732935905457}, 'Confidence': 99.5052261352539}, {'BoundingBox': {'Width': 0.2420956939458847, 'Height': 0.6571153998374939, 'Left': 0.16403935849666595, 'Top': 0.2835889756679535}, 'Confidence': 62.047969818115234}]\n",
            "Transportation : 99.5052261352539[]\n",
            "Vehicle : 99.5052261352539[]\n",
            "Animal : 99.31156158447266[]\n",
            "Canine : 99.31156158447266[]\n",
            "Dog : 99.31156158447266[{'BoundingBox': {'Width': 0.2342192381620407, 'Height': 0.5544285178184509, 'Left': 0.17188990116119385, 'Top': 0.38754960894584656}, 'Confidence': 99.31156158447266}]\n",
            "Mammal : 99.31156158447266[]\n",
            "Pet : 99.31156158447266[]\n",
            "Plant : 97.7978286743164[]\n",
            "Tree : 97.7978286743164[]\n",
            "Wheel : 97.44068145751953[{'BoundingBox': {'Width': 0.24615757167339325, 'Height': 0.314919650554657, 'Left': 0.4911452829837799, 'Top': 0.41441887617111206}, 'Confidence': 97.44068145751953}, {'BoundingBox': {'Width': 0.04160372540354729, 'Height': 0.052048470824956894, 'Left': 0.8289476037025452, 'Top': 0.24493974447250366}, 'Confidence': 80.39229583740234}, {'BoundingBox': {'Width': 0.04330078884959221, 'Height': 0.05542082339525223, 'Left': 0.6620650887489319, 'Top': 0.2236187756061554}, 'Confidence': 73.15531158447266}]\n",
            "Car : 97.36234283447266[{'BoundingBox': {'Width': 0.29039180278778076, 'Height': 0.1698329597711563, 'Left': 0.6048358678817749, 'Top': 0.12719792127609253}, 'Confidence': 97.36234283447266}]\n",
            "Accessories : 95.96794128417969[]\n",
            "Strap : 95.96794128417969[]\n",
            "Potted Plant : 95.61145782470703[]\n",
            "Architecture : 80.92571258544922[]\n",
            "Building : 80.92571258544922[]\n",
            "Outdoors : 80.92571258544922[]\n",
            "Shelter : 80.92571258544922[]\n",
            "Motorcycle : 80.88300323486328[{'BoundingBox': {'Width': 0.07584317028522491, 'Height': 0.1127498671412468, 'Left': 0.07209309190511703, 'Top': 0.12209328263998032}, 'Confidence': 80.88300323486328}]\n",
            "Vegetation : 68.34353637695312[]\n",
            "Nature : 68.1030044555664[]\n",
            "Alloy Wheel : 64.00493621826172[]\n",
            "Car Wheel : 64.00493621826172[]\n",
            "Tire : 64.00493621826172[]\n",
            "Husky : 60.894290924072266[]\n",
            "Puppy : 57.95663070678711[]\n",
            "Herbal : 57.93125534057617[]\n",
            "Herbs : 57.93125534057617[]\n",
            "Path : 57.627349853515625[]\n",
            "Grass : 57.132530212402344[]\n",
            "City : 57.040775299072266[]\n",
            "Road : 57.040775299072266[]\n",
            "Street : 57.040775299072266[]\n",
            "Urban : 57.040775299072266[]\n",
            "License Plate : 55.70207214355469[]\n",
            "Soil : 55.37385177612305[]\n",
            "Slate : 55.242645263671875[]\n",
            "Park : 55.22623825073242[]\n",
            "Jar : 55.19215393066406[]\n",
            "Planter : 55.19215393066406[]\n",
            "Pottery : 55.19215393066406[]\n",
            "Vase : 55.19215393066406[]\n",
            "Walkway : 55.17646789550781[]\n",
            "Yard : 55.003910064697266[]\n"
          ]
        }
      ],
      "source": [
        "import boto3\n",
        "\n",
        "def detect_labels_local_file(photo):\n",
        "\n",
        "    client=boto3.client('rekognition', region_name=region_name, aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key)\n",
        "    l = []\n",
        "    with open(photo, 'rb') as image:\n",
        "        response = client.detect_labels(Image={'Bytes': image.read()})\n",
        "\n",
        "    print('Detected labels in ' + photo)\n",
        "    for label in response['Labels']:\n",
        "        print (label['Name'] + ' : ' + str(label['Confidence']) + str(label[\"Instances\"]))\n",
        "\n",
        "\n",
        "photo='/content/image.jpg'\n",
        "detect_labels_local_file(photo)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
